home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pcrsep89.arc / AVG.BAS next >
BASIC Source File  |  1990-03-21  |  1KB  |  47 lines

  1. ' Quick Basic program that sets each cell to the average of its neighborhood
  2.  
  3. DEFINT A-Z
  4. ' $Include: 'CA.BI'
  5.  
  6. DO
  7.     CLS
  8.     Rows = 80                                            ' Assumes an EGA/VGA adapter
  9.     Cols = 80                                            '   and monitor
  10.     RowRpt = 4
  11.     ColRpt = 8
  12.  
  13.     x% = CAINIT(6, VARPTR(CaArray(0)))            'Initialize the world
  14.     CALL CASIZE (Rows, Cols, RowRpt, ColRpt)    'Set its size
  15.  
  16.     RANDOMIZE TIMER
  17.     CALL CABORDER(int(rnd * 256))                    'Pick value for invisible border
  18.  
  19.     FOR i = 1 TO Rows
  20.         FOR j = 1 TO Cols
  21.             k = INT(RND * 256)                        'Random value for each cell
  22.         CALL CASET(i, j, k)
  23.         NEXT j
  24.     NEXT i
  25.     CASHOW                                                'Show starting values
  26.  
  27.     DO WHILE INKEY$ = ""
  28.         CAGEN                                                'Loop until user wants out
  29.     LOOP
  30.  
  31.     CARESET
  32.     CLS
  33.     Print "Do it again? ==> ";
  34.     DO
  35.         Char$ = Ucase$(Input$(1))
  36.     Loop until instr("YN",Char$)
  37. LOOP While Char$ = "Y"
  38. END
  39.  
  40. FUNCTION CACELL%                                        'Do the work here
  41.     sum = 0
  42.     for i = NorthWest to SouthEast                'Add up all the neighbors
  43.         sum = sum + CaArray(i)                        ' (including self)
  44.     next i
  45.     CaCell = sum \ 9                                    'Become as average as possible
  46. END FUNCTION
  47.